﻿<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@ taglib prefix="s" uri="http://shiro.apache.org/tags" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="fns" uri="/WEB-INF/tlds/fns.tld" %>
<%@ include file="/WEB-INF/view/include/inc.jsp"%>
<!DOCTYPE html>
<html lang="en">
<head>
 	<%@ include file="/WEB-INF/view/jQgrid.jsp"%>
</head>
<body>
<div class="container-fluid" id="main-container">
    <div id="page-content" class="clearfix">
        <div class="row-fluid">
            <div class="row-fluid">
                <!-- 检索  -->
                <div class="ibox-title" style="border-color: white;">
                    <div class="row">
                        <div class="col-sm-12">
                            <div class="form-group form-inline">
                                <span>公司名称：</span>
                                <input id="name" type="text" placeholder="请输入公司名称" class="input-sm form-control">
                                <span> 行业名称：</span>
								<input type="text" class="form-control" id="industryName"
										onclick="openTree('industry');" placeholder="请选择行业"
										readonly="readonly"  name="industryNames"/> <input type="hidden" name="industryId"
										id="industryId" />
								<span> 所属区域：</span>
								<select  id="province"  class="form-control"></select>
								<select  id="city" class="form-control" style="display:none;" ></select>
								<select  id="county"  class="form-control" name="areaId" style="display:none;" ></select>	
                             </div>
                        </div>
                        <div class="col-sm-12">
							<div class="form-group form-inline">
							 <span>客户状态：</span>
                             <select class="form-control"  id="status" name="status" >
								<option value="">==请选择==</option>
								<c:forEach items="${fns:getDictList('company_status')}" var="cstatus">
								<option value="${cstatus.value }">${cstatus.valueName }</option>
								</c:forEach>
						    </select>
							<span> 创建人：</span>
							<input type="text" class="form-control" id="userName"
										onclick="openTree('user');" placeholder="请选择创建人"
										readonly="readonly"  name="userName"/> <input type="hidden" name="userId"
										id="userId" />
							<span>起止时间：</span>
							<input id="startDate" type="text" placeholder="请输入开始时间" class="input-sm form-control form_datetime" readonly="readonly">—
							<input id="endDate" type="text" placeholder="请输入结束时间" class="input-sm form-control form_datetime" readonly="readonly">
							</div>
						</div>
						<div class="col-sm-12">
						    <div class="form-group form-inline">
							    <a id="find_btn" type="button" class="btn btn-sm btn-primary"> 搜索</a> 
							    <a id="reset_btn" type="button" class="btn btn-sm btn-warning"> 重置</a>
	                            <s:hasPermission name="company:add">
	                            	<a  class="btn btn-sm btn-success" onclick="showadd();"> 添加</a>
	                            </s:hasPermission>
							</div>
						</div>
                    </div>
                </div>
                <!-- biaogebigin -->
                <div class="ibox-content" style=" padding-left: 0px; margin-top: 10px;">
                    <div class="jqGrid_wrapper">
                        <table id="table_list"></table>
                        <div id="pager_list"></div>
                    </div>
                </div>
                <!-- tableover -->
            </div>
            <!-- PAGE CONTENT ENDS HERE -->

        </div>
        <!--/row-->
    </div>
    <!--/#page-content-->
</div>
<!--/.fluid-container#main-container-->
<script type="text/javascript">
$(".form_datetime").datetimepicker({
	  minView: "month",//设置只显示到月份
	  format : "yyyy-mm-dd",//日期格式
	  autoclose:true,//选中关闭
	  todayBtn: true,//今日按钮
    language:  'zh-CN',
});
    $(top.hangge());
        $.jgrid.defaults.styleUI = "Bootstrap";
        $("#table_list").jqGrid({
            url: '<%=contextPath%>/company/listData',
            datatype: "json",
            postData: {}, //发送数据
            autowidth: true,
            rownumbers: true,
            shrinkToFit: true,
            mtype: "post",
            sortname: 'createDate',
            sortorder: "desc",
            rowNum: 15,
            rowList: [15, 30, 60],
            colNames: ["id","公司名称","公司性质","公司行业","公司规模","所属地区","投资人或股东", "创建人","创建时间","数据状态","组织架构","操作"],
            colModel: [{
                name: "id",
                index: "id",
                hidden: true
            }, {
                name: "name",
                index: "name",
                width: 100,
                frozen : true
            }, {
                name: "dictNature",
                index: "dictNature",
                width: 60
            }, {
                name: "industryNames",
                index: "industryNames",
                width: 100,
                frozen : true
            }, {
                name: "dictScale",
                index: "dictScale",
                width: 60
            }, {
                name: "area.treeNames",
                index: "area.treeNames",
                width: 100
            }, {
                name: "investor",
                index: "investor",
                width: 100
            }, {
                name: "createUser.truename",
                index: "createUser.truename",
                width: 45
            }, {
                name: "createDate",
                index: "createDate",
                width: 80,
                editable:false,formatter:"date",formatoptions: {srcformat:'Y-m-d H:i:s',newformat:'Y-m-d H:i:s'}
            }, {
                name: "dictStatus",
                index: "dictStatus",
                width: 75
            },  {
                formatter: function (value, options, row) {
                    return "<a class='btn-sm btn-mini btn-warning' onclick='showorg(&quot;" + row.id + "&quot;)'>查看</a>";
                },
                width: 60
            },  {
                formatter: function (cellvalue, options, row) {
                    return " <s:hasPermission name="company:detail"><a class='btn-sm btn-mini btn-info' title='查看' onclick='showeye(&quot;" + row.id + "&quot;)'><i class='icon-eye-open'></i></a></s:hasPermission> "
                           +" <s:hasPermission name="company:edit"><a class='btn-sm btn-mini btn-warning' title='修改' onclick='showedit(&quot;" + row.id + "&quot;)'><i class='icon-edit'></i></a></s:hasPermission> "     
                           + " <s:hasPermission name="company:delete"><a class='btn-sm btn-mini btn-danger' title='删除' onclick='del(&quot;" + row.id + "&quot;)'><i class='icon-trash'></i></a></s:hasPermission> ";
                },
                width: 100
            }],
            height: $(window).height() - 170,
            pager: "#pager_list",
            multiselect: true,//多选按钮
            //multiboxonly: true,
            viewrecords: true,
            hidegrid: false
        });
        //表格自适应高宽
        $(window).bind("resize", function () {
            var b = $(".jqGrid_wrapper").width();
            $("#table_list").setGridWidth(b);
            $("#table_list").setGridHeight($(window).height() - 170);
        })
        $("#table_list").navGrid('#pager_list', {edit: false, add: false, del: false, search: false})
        /* 判断是否有添加权限 */
        //检索
        $("#find_btn").click(function () {
            var name = $("#name").val();
            var status = $("#status").val();
            var userId = $("#userId").val();
            var areaId = $("#county").val();
             //行业
            var industryId = $("#industryId").val();
            //开始时间
            var startDate = $('#startDate').val();
            if(startDate!=""){
          	  startDate=startDate+" 00:00:00"
            }
            //结束时间
             var endDate = $('#endDate').val();
             if(endDate!=""){
             	endDate=endDate+" 23:59:59";
             }
            $("#table_list").jqGrid('setGridParam', {
                postData: {
                	'name': name,
                	'status':status,
                	'industryId':industryId,
                	'createuserid':userId,
                	'expectedCity':areaId,
                	'startDate':startDate,
                	'endDate':endDate
                	}, //发送数据
                page: 1
            }).trigger("reloadGrid"); //重新载入
        });
        $("#reset_btn").click(function(){ 
        	location.reload();
		});
        $.ajax({//查询省
    		url:"<%=contextPath%>/area/getAreaJson",
    		data:{pid:0,level:1},
    		type:"post",
    		dataType:"json",
    		success:function(data){
    			var htm='';
    			$("#province").append('<option value="">==请选择省直辖市==</option>');
    			$.each(data,function(i,item){
    				$("#province").append("<option value='" + item.id + "'>" + item.name + "</option>");
    			});
    		}
    	});	
    	$("#province").change(function(){//查询市
    		var pid = $(this).val();
    		var city = $("#city");
    		var county = $("#county");
    		$("#city").show();
    		$("#county").hide();
    		if($("#city").children().length > 0) {
    			city.empty();
    		}
    		if($("#county").children().length > 0) {
    			county.empty();
    		}
    		$.ajax({//查询省
    			url:"<%=contextPath%>/area/getAreaJson",
    			data:{pid:pid,level:2},
    			type:"post",
    			dataType:"json",
    			success:function(data){
    				$("#city").append('<option value="">==请选择市州==</option>');
    				$.each(data,function(i,item){
    					$("#city").append("<option value='" + item.id + "'>" + item.name + "</option>");
    				});
    			}
    		})
    	});
    	$("#city").change(function(){//查询市
    		var pid = $(this).val();
    		var county = $("#county");
    		$("#county").show();
    		if($("#county").children().length > 0) {
    			county.empty();
    		}
    		$.ajax({//查询省
    			url:"<%=contextPath%>/area/getAreaJson",
    			data:{pid:pid,level:3},
    			type:"post",
    			dataType:"json",
    			success:function(data){
    				$("#county").append('<option value="">==请选择县区==</option>');
    				$.each(data,function(i,item){
    					$("#county").append("<option value='" + item.id + "'>" + item.name + "</option>");
    				});
    			}
    		})
    	});
    //删除
    function del(id) {
        swalopen(id, "<%=contextPath%>/company/delete");
    };
    //查看
    function showeye(id) {
       window.open("<%=contextPath%>/company/detailView?id=" + id);
    }
    //修改
    function showedit(id) {
        openyem("修改公司", "<%=contextPath%>/company/editView?id=" + id, 800, 750);
    }
    
  //添加
    function showadd(id) {
        openyem("添加公司", "<%=contextPath%>/company/addView", 800, 750);
    }
  //查看组织
   function showorg(id) {
	   openyem("组织架构", "<%=contextPath%>/organize/list?companyId="+id, 800, 750);
	}
    function openTree(obj,num){
	     var ids = $("#"+obj+"Id").val();
	   	 var diag = new top.Dialog();
		 diag.Drag=true;
		 diag.Title ="请选择";
		 diag.URL = '<%=contextPath %>/'+obj+'/openZtree?ids='+ids;
		 diag.Width = 250;
		 diag.Height = 400;
		 diag.CancelEvent = function(){ //关闭事件
			 var tempid = diag.innerFrame.contentWindow.document.getElementById('tempids').value;
			 var tempname = diag.innerFrame.contentWindow.document.getElementById('tempnames').value;
			if(tempid.length!==0){
				if(typeof(num)=="undefined"){ 
					$("#"+obj+"Id").val(tempid);
					$("#"+obj+"Name").val(tempname);
				}else{
					$("#"+obj+num+"Id").val(tempid);
					$("#"+obj+num+"Name").val(tempname);
				}
			}
			diag.close();
		 };
		 diag.show();
	}
</script>
</body>
</html>

